package com.rover022.flixelgame.ui.equippackage
{
	import com.bit101.components.Window;
	import com.greensock.events.LoaderEvent;
	import com.rover022.flixelgame.manager.EventHelper;
	import com.rover022.flixelgame.manager.ItemManager;
	import com.rover022.flixelgame.manager.PlayerManager;
	import com.rover022.flixelgame.ui.equipupgrade.GeneralityGridUI;
	import com.rover022.flixelgame.ui.equipupgrade.GeneralityPackageUI;
	import com.rover022.flixelgame.utils.MiniComponentTool;
	import com.rover022.flixelgame.vo.ItemVo;
	import flash.display.Sprite;
	import flash.events.MouseEvent;

	public class EquipPackage extends GeneralityPackageUI
	{
		public function EquipPackage()
		{
			initUI();
		}

		override public function initUI(e:LoaderEvent = null):void
		{
			var ui:Window = MiniComponentTool.getPopWindow("EquipPackage", close);
			addChild(ui);
			gridContainer = new Sprite();
			ui.content.addChild(gridContainer);
			var array:Array = PlayerManager.getInstance().getAllItems();
			for (var i:int = 0; i < array.length; i++)
			{
				var itemvo:ItemVo = array[i] as ItemVo;
				var grid:GeneralityGridUI = ItemManager.getInstance().makeGeneralityGrid(itemvo);
				EventHelper.addEventListener(grid, MouseEvent.CLICK, gridClick);
				addGridToContainer(grid, false);
			}
			sortGrid();
		}

		override public function addGridToContainer(param0:GeneralityGridUI, isSort:Boolean = true):void
		{
			gridContainer.addChild(param0);
			if (isSort)
			{
				sortGrid();
			}
		}

		override public function sortGrid():void
		{
			var array:Array = getAllGrids();
			for (var i:int = 0; i < array.length; i++)
			{
				var item:GeneralityGridUI = array[i];
				item.x = (i % 4) * gridSize;
				item.y = int(i / 4) * gridSize;
			}
		}
	}
}
